package com.ksm.zyz.common.util;

public class convertCharUtil {
	public static String underscoreName(String name) {
	    StringBuilder result = new StringBuilder();
	    if (name != null && name.length() > 0) {
	        result.append(name.substring(0, 1).toLowerCase());
	        for (int i = 1; i < name.length(); i++) {
	            String s = name.substring(i, i + 1);
	            if (s.equals(s.toUpperCase()) && !Character.isDigit(s.charAt(0))) {
	                result.append("_");
	            }
	            result.append(s.toLowerCase());
	        }
	    }
	    return result.toString();
	}
	 
	public static String camelName(String name) {
	    StringBuilder result = new StringBuilder();
	    // 快速检查
	    if (name == null || name.isEmpty()) {
	        // 没必要转换
	        return "";
	    } else if (!name.contains("_")) {
	        // 不含下划线，仅将首字母小写
	        return name.substring(0, 1).toLowerCase() + name.substring(1);
	    }
	    String camels[] = name.split("_");
	    for (String camel :  camels) {
	        if (camel.isEmpty()) {
	            continue;
	        }
	        if (result.length() == 0) {
	            result.append(camel.toLowerCase());
	        } else {
	            result.append(camel.substring(0, 1).toUpperCase());
	            result.append(camel.substring(1).toLowerCase());
	        }
	    }
	    return result.toString();
	}
    public static void main(String[] args) {  
        String lineToHump = "f_parent_no_leader";  
        System.out.println(lineToHump);//fParentNoLeader  
        System.out.println(camelName(lineToHump));//f_parent_no_leader  
    }  
}
